<%@page import="com.wanmait.shoppingsys.vo.UserInfo"%>
<%@page import="com.wanmait.shoppingsys.vo.Type"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.wanmait.shoppingsys.util.ShopCar"%>
<%@page import="java.util.List"%>
<%@page import="com.wanmait.shoppingsys.vo.Trade"%>
<%@page import="com.wanmait.shoppingsys.vo.City"%>
<%@page import="com.wanmait.shoppingsys.vo.Specialty"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getServletContext().getContextPath();
%>
<jsp:include page="/TypeController?action=type"></jsp:include>
<jsp:include page="/inc/header.jsp"></jsp:include>


<div class="search_bar clearfix">
	<a href="index.jsp" class="logo fl"><img
		src="<%=path%>/images/logo.png"></a>
	<form class="search_con fl"
		action="<%=path%>/SpecialtyController?action=serach" method="post">
		<input type="text" class="input_text fl" name="serach_produit"
			placeholder="搜索商品"> <input type="submit" class="input_btn fr"
			name="serach" value="搜索">
	</form>

	<div class="guest_cart fr">
		<a href="<%=path%>/order/index.jsp" class="cart_name fl">我的购物车</a>
		<%
			ShopCar shopCar = (ShopCar) session.getAttribute("shopCar");
			UserInfo userinfo = (UserInfo) session.getAttribute("userinfo");
			if (userinfo == null) {
		%>
		<div class="goods_count fl" id="show_count">0</div>
		<%
			} else {
				if (shopCar == null) {
		%>
		<div class="goods_count fl" id="show_count">0</div>
		<%
			} else {
		%>
		<div class="goods_count fl" id="show_count"><%=shopCar.getTotalNumber()%></div>
		<%
			}
		%>
		<%
			}
		%>
	</div>
</div>

<div class="navbar_con">
	<div class="navbar clearfix">
		<div class="subnav_con fl">
			<h1>全部商品分类</h1>
			<span></span>
			<ul class="subnav">
				<%
					String cl[] = {"fruit", "dryfruit", "liquor", "egg", "tea", "sea"};
				%>
				<%
					ArrayList<Type> types = (ArrayList<Type>) request.getAttribute("types");
					for (int i = 0; i < types.size(); i++) {
						Type type = types.get(i);
				%>
				<li><a href="<%=path%>/index.jsp#model0<%=type.getId()%>"
					class="<%=cl[i]%>"><%=type.getKind()%></a></li>
				<%
					}
				%>
			</ul>
		</div>
		<ul class="navlist fl">
			<li><a href="<%=path%>/index.jsp">首页</a></li>
			<li class="interval">|</li>
			<li><a href="">抽奖</a></li>
			<li class="interval">|</li>
			<li><a href="<%=path%>/specialty/findbycity.jsp">按城市查找</a></li>
		</ul>
	</div>
</div>	
	<%
		Specialty specialty = (Specialty) request.getAttribute("specialty");
	%>
	<div class="breadcrumb">
		<a href="<%=path%>">全部分类</a> <span>></span> 
		<a href="<%=path%>/SpecialtyController?action=findAll&id=<%=specialty.getType().getId()%>"><%=specialty.getType().getKind()%></a>
		<span>></span> <a href="#">商品详情</a>
	</div>


	<div class="goods_detail_con clearfix">
		<div class="goods_detail_pic fl">
			<img src="<%=path%>/upload/goods/<%=specialty.getPic()%>">
		</div>


		<div class="goods_detail_list fr">

			<h3><%=specialty.getName()%></h3>
			<p>
				产地：<%=specialty.getCity().getName()%></p>
			<div class="prize_bar">
				<span class="show_pirze">¥<em id="price1"><%=specialty.getPrice()%></em></span>
				<%
					if (specialty.getType().getId() == 3) {
				%>
				<span class="show_unit">单位:&nbsp(<%=specialty.getPrice()%>/瓶)
				</span>
				<%
					} else {
				%>
				<span class="show_unit">单位:&nbsp(<%=specialty.getPrice()%>/500g)
				</span>
				<%
					}
				%>
			</div>

			<div class="goods_num clearfix">
				<div class="num_name fl">数 量：</div>
				<div class="num_add fl">
					<input type="text" class="num_show fl" id="num_show" value="1">

					<a class="add fr" id="add fr" onclick="add()">+</a> 
					<a class="minus fr" id="minus fr" onclick="diff()">-</a>
				</div>
			</div>

			<div class="total">总价：<em id="price"><%=specialty.getPrice()%></em><em>元</em></div>
			<div class="operate_btn">

				<a class="buy_btn"  onclick="buy()">立即购买</a>
				<a class="add_cart" id="add_cart" onclick="shopcar()">加入购物车</a>	
				<a class="good"  onclick="addcollect()"><img alt="幻灯片" src="<%=path %>/upload/goods/11111.png" ></a>			
 
			</div>
		</div>
	</div>

<div class="main_wrap clearfix">
	<div class="l_wrap fl clearfix">
		<div class="new_goods">
			<h3>新品推荐</h3>
			<ul>
				<li><a
					href="/ShoppingSys/SpecialtyController?action=detailed&id=112"><img
						src="<%=path%>/upload/博山猕猴桃.jpg"></a>
					<h4>
						<a href="#">博山猕猴桃</a>
					</h4>
					<div class="prize">￥50</div></li>
				<li><a
					href="/ShoppingSys/SpecialtyController?action=detailed&id=31"><img
						src="<%=path%>/upload/灵山岛海参.jpg"></a>
					<h4>
						<a href="#">灵山岛海参</a>
					</h4>
					<div class="prize">￥16.80</div></li>
			</ul>
		</div>
	</div>

	<div class="r_wrap fr clearfix">
		<ul class="detail_tab clearfix">
			<li class="active">商品介绍</li>
			<li class="com">评论</li>

		</ul>

		<div class="tab_content">
			<dl class="info">
				<dt>商品详情：</dt>
				<dd><%=specialty.getIntroduce()%></dd>
			</dl>
		</div>
		<div class="showcontent" style="display: none">

			<textarea rows="10" cols="137" class="content" placeholder="留言内容"></textarea>
			<div>
				<input type="button" value="发布留言" class="addcom">
			</div>
		</div>
	</div>
</div>

<jsp:include page="/inc/footer.jsp"></jsp:include>


<script type="text/javascript">


function refreshComment(){

	$.get("<%=path%>/EvaluationController?action=listComment&specialtyId=<%=specialty.getId()%>",function(mes){
		//console.log(mes);
		$(".content").val("");
		$(".info").html(mes);
		
	});
}
function refreshintroduce(){

	$.get("<%=path%>/EvaluationController?action=listint&specialtyId=<%=specialty.getId()%>",function(mes){
		//console.log(mes);
		$(".info").html(mes);
		
	});
}

$(function() {
	$(".com").click(function(){
		$(".com").css("border-top","2px solid #37ab40")
		$(".com").css("border-left","1px solid #37ab40")
		$(".com").css("border-right","1px solid #37ab40")
		$(".com").css("height","35px")
		$(".active").css("border-top","none")
		$(".active").css("border-left","none")
		$(".active").css("border-right","none")
		$(".active").css("height","32px")
		$(".showcontent").css("display","block")
		
		refreshComment();
	});
	
	$(".active").click(function() {
		$(".active").css("border-top","2px solid #37ab40")
		$(".active").css("border-left","1px solid #37ab40")
		$(".active").css("border-right","1px solid #37ab40")
		$(".active").css("height","35px")
		$(".com").css("border-top","none")
		$(".com").css("border-left","none")
		$(".com").css("border-right","none")
		$(".com").css("height","32px")
		$(".showcontent").css("display","none")
		refreshintroduce();
	})
});

		$(function(){
			$(".addcom").click(function() {
				var action = "/ShoppingSys/EvaluationController?action=add";
				
				var specialtyId=<%=specialty.getId()%>;
				var content = $(".content").val();
				
				$.post(action,{specialtyId:specialtyId,content:content},function(mes){
					
					refreshComment();
				});
			})
		}); 

			
		
	
	
function add() {
	var num_show=$("#num_show");
	var tx=num_show.attr("value");
	var txc=parseInt(tx);
	txc=txc+1;
	num_show.attr("value",txc)
	
	var price1=$("#price1")
	
	var pri=price1.html();
	
	var prix=parseFloat(pri);

	var price=$("#price");
	var prx=Math.round(prix*txc*10)/10+"";
	if(prx.indexOf(".")==-1){
		prx = prx+".0";
		price.html(prx);
	}else{
		price.html(prx);
	}
		
	
	
	
	
}

function diff() {
	var num_show=$("#num_show");
	var tx=num_show.attr("value");
	var txc=parseInt(tx);
	if(txc<=1){return;}
	txc=txc-1;
	num_show.attr("value",txc)
	
	var price1=$("#price1")
	
	var pri=price1.html();
	
	var prix=parseFloat(pri);
	
	
	var price=$("#price");
	var prx=Math.round(prix*txc*10)/10+"";
	if(prx.indexOf(".")==-1){
		prx = prx+".0";
		price.html(prx);
	}else{
		price.html(prx);
	}
}

function buy() {
//	alert("222")
	var num_show=$("#num_show");
	var tx=num_show.val();
	//var txc=parseInt(tx);
	console.log(tx);
	window.location.href="<%=path%>/GoodsController?action=buy&id=<%=specialty.getId()%>&count="+tx;
}

function shopcar() {
//	alert("111")
	var num_show=$("#num_show");
	var tx=num_show.val();
	//var txc=parseInt(tx);
	console.log(tx);
	window.location.href="<%=path%>/ShopCarController?action=buy&id=<%=specialty.getId()%>&count="+ tx;
	}


function addcollect(){
	var num_show=$("#num_show");
	var tx=num_show.val();
	console.log(tx);
	window.location.href="<%=path %>/ShopCarController?action=addbuy&id=<%=specialty.getId() %>";
	
}

</script >








